<script setup lang="ts">
import { has } from 'lodash-es'
import { CertList, CertRecord } from './components'

const route = useRoute()
const router = useRouter()

type ModuleKeys = 'list' | 'record'

const componentMap: Record<ModuleKeys, Component> = {
  list: CertList,
  record: CertRecord,
}
const currComponent = computed(() => {
  const mod = String(route.params?.module || '')
  if (has(componentMap, mod)) {
    return componentMap[mod as ModuleKeys]
  }
  return CertList
})

onBeforeMount(() => {
  const mod = String(route.params?.module || '')
  if (!mod) {
    router.replace({
      name: 'CertManagement',
      params: {
        module: 'list',
      },
    })
  }
})
</script>

<template>
  <component :is="currComponent" />
</template>

<style scoped></style>
